package top.shmly.universal.base.validator;




import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * @Author: jp
 * @Date: 2019/5/28
 * @Time: 15:09
 * @Description:
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {

    private final Pattern pattern = Pattern.compile("^1[0-9]{10}$");

    @Override
    public void initialize(Phone phone) {
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (StringUtils.isBlank(value)) return false;
        return pattern.matcher(value).matches();
    }
}
